package com.luoshupeng.multidatasource.controller.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.luoshupeng.multidatasource.primary.entity.User;
import com.luoshupeng.multidatasource.primary.service.UserService;

/**
 * Created by luoshupeng on 2018-03-20 10:35
 */
@Controller
@RequestMapping("/user/*")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("list")
    public ResponseEntity<List<User>> list() {
        return new ResponseEntity<>(userService.list(), HttpStatus.OK);
    }
    
    @GetMapping("showUser")
    public String findAll(HttpServletRequest request) {
        request.setAttribute("user", "hello thymeleaf");
        request.getSession().setAttribute("shj","帅哥");
        return "user";
    }
    @GetMapping("showUserList")
    public String showUserList(Model model) {
        User single = new User();
        single.setId(1001);
        single.setName("张无忌");
        single.setAge(18);
        List<User> list = userService.list();
        model.addAttribute("singlePerson",single);
        model.addAttribute("people",list);
        return "user-list";
    }
}
